package com.play.ballen.mall.adapter

import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.play.ballen.R
import com.play.ballen.mall.entity.MallRecordInfo
import com.play.ballen.mall.ui.MallRecordActivity
import com.yuven.baselib.utils.ResourceUtil

class MallRecordAdapter(data: MutableList<MallRecordInfo>, val type: String) :
    BaseQuickAdapter<MallRecordInfo, BaseViewHolder>(R.layout.item_mall_buy_record, data) {

    override fun convert(holder: BaseViewHolder, item: MallRecordInfo) {
        holder.setText(
            R.id.tvLevel,
            ResourceUtil.getString(if (type == MallRecordActivity.TYPE_RECORD_BUY) R.string.mall_record_level_buy else R.string.mall_record_level_sale)
        )
        holder.setText(
            R.id.tvCount,
            ResourceUtil.getString(if (type == MallRecordActivity.TYPE_RECORD_BUY) R.string.mall_record_count_buy else R.string.mall_record_count_sale)
        )
        holder.setText(
            R.id.tvPrice,
            ResourceUtil.getString(if (type == MallRecordActivity.TYPE_RECORD_BUY) R.string.mall_record_price_buy else R.string.mall_record_price_sale)
        )
        holder.setText(
            R.id.tvTime,
            ResourceUtil.getString(if (type == MallRecordActivity.TYPE_RECORD_BUY) R.string.mall_record_time_buy else R.string.mall_record_time_sale)
        )

        val tvNoValue = holder.getView<TextView>(R.id.tvNoValue)
        val tvLevelValue = holder.getView<TextView>(R.id.tvLevelValue)
        val tvCountValue = holder.getView<TextView>(R.id.tvCountValue)
        val tvPriceValue = holder.getView<TextView>(R.id.tvPriceValue)
        val tvTimeValue = holder.getView<TextView>(R.id.tvTimeValue)

        item.run {
            tvNoValue.text = ResourceUtil.getString(R.string.home_property_no_text, no)
            tvLevelValue.text = name
            tvCountValue.text = num
            tvPriceValue.text =
                if (type == MallRecordActivity.TYPE_RECORD_BUY) {
                    ResourceUtil.getString(R.string.home_property_price_text, price)
                } else {
                    ResourceUtil.getString(R.string.price_unit_bmt, total)
                }
            tvTimeValue.text = add_time
        }
    }

}